package com.framework.Interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServerBasePathInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean superResult = super.preHandle( request, response, handler );
        String scheme = request.getScheme();
        String serverName = request.getServerName();
        int remotePort = request.getServerPort();
        String contextPath = request.getServletContext().getContextPath();
        String basepath = scheme + "://" + serverName + ":" + remotePort + "/" + contextPath;
        request.setAttribute( "basepath", basepath );
        return superResult;
    }
}
